<?php

$getPetInfo = fetch("SELECT * FROM user_pets2 WHERE owner = '$userid' AND id = '$feed_to' AND game = '$game'");
$getPetInfo2 = fetch("SELECT * FROM pets2 WHERE game = '$game' AND id = '$getPetInfo[species]'");

if ($getPetInfo[hunger] >= "10")
{
	die("
		<br><center>
		<table width=380 cellspacing=0>
		<tr>
		<td bgcolor=$topAndBottomBG>
		<center><b><font color=$topAndBottomText>Selected Item</font></b></center>
		</td>
		<td width=300 bgcolor=$topAndBottomBG>
		<center><b><font color=$topAndBottomText>Item Details</font></b></center>
		</td>
		</tr>
		<tr height=100>
		<td valign=middle>
		<p align=center><img src=images/user_images/opg_$game/items/item_$find_item2[id].gif>
		<br>
		<b>$find_item2[item_name]</b>
		</td>
		<td width=300>
		<p 	align=center>You are too full to eat the $find_item2[item_name].<br>($find_item[parts_left]/$find_item2[parts] Parts Left)<br><a href=myitems.php?game=$game>Back to Items</a></p>
		</td>
		</tr>
		</table>
		</center>
	");
}

if (!$getPetInfo[id])
{
		die("
		<br><center>
		<table width=380 cellspacing=0>
		<tr>
		<td bgcolor=$topAndBottomBG>
		<center><b><font color=$topAndBottomText>Selected Item</font></b></center>
		</td>
		<td width=300 bgcolor=$topAndBottomBG>
		<center><b><font color=$topAndBottomText>Item Details</font></b></center>
		</td>
		</tr>
		<tr height=100>
		<td valign=middle>
		<p align=center><img src=images/user_images/opg_$game/items/item_$find_item2[id].gif>
		<br>
		<b>$find_item2[item_name]</b>
		</td>
		<td width=300>
		<p 	align=center>That is not your pet.<br>($find_item[parts_left]/$find_item2[parts] Parts Left)<br><a href=myitems.php?game=$game>Back to Items</a></p>
		</td>
		</tr>
		</table>
		</center>
	");
}

$new_hunger = $getPetInfo[hunger] + $find_item2[magic_num];

mysql_query("UPDATE user_pets2 SET hunger=$new_hunger WHERE id = '$feed_to' AND game = '$game'");

if ($find_item[parts_left] <= 1)
{
	mysql_query("DELETE FROM usersitems2 WHERE id = '$id' AND owner = '$userid' AND game = '$game'");
}
else
{
	mysql_query("UPDATE usersitems2 SET parts_left=$find_item[parts_left]-1 WHERE owner = '$userid' AND id = '$id' AND game = '$game'");
}

$explodeAttacks = explode(", ", $getPetInfo2[item_likes]);
$countAttacks = count($explodeAttacks) - 1;

for ($a = 0; $a <= $countAttacks;)
{
	if ($explodeAttacks[$a] == "$find_item2[item_name]")
	{
		$happyLevel = 10;
		$petLine = "I really liked that $find_item2[item_name]! You should get those for me more often!";
		$a = $countAttacks;
	}
	$a++;
}

$explodeAttacks = explode(", ", $getPetInfo2[item_dislikes]);
$countAttacks = count($explodeAttacks) - 1;

for ($a = 0; $a <= $countAttacks;)
{
	if ($explodeAttacks[$a] == "$find_item2[item_name]")
	{
		$happyLevel = -10;
		$petLine = "Sick!! That $find_item2[item_name] was disgusting! Please don't feed me those again!!";
		$a = $countAttacks;
	}
	$a++;
}

if ($petLine)
{
	$petLine = "<b>$getPetInfo[name] says \"</b>$petLine\"<br>";
	$newAttitude = $getPetInfo[attitude] + $happyLevel;
	mysql_query("UPDATE user_pets2 SET attitude=$newAttitude WHERE id = '$getPetInfo[id]' AND game = '$game'");
}

$minus1 = $find_item[parts_left] - 1;
print "
		<br><center>
		<table width=380 cellspacing=0>
		<tr>
		<td bgcolor=$topAndBottomBG>
		<center><b><font color=$topAndBottomText>Selected Item</font></b></center>
		</td>
		<td width=300 bgcolor=$topAndBottomBG>
		<center><b><font color=$topAndBottomText>Item Details</font></b></center>
		</td>
		</tr>
		<tr height=100>
		<td valign=middle>
		<p align=center><img src=images/user_images/opg_$game/items/item_$find_item2[id].gif>
		<br>
		<b>$find_item2[item_name]</b>
		</td>
		<td width=300>
		<p align=center>You have fed the $find_item2[item_name] to $getPetInfo[name].<br>They now feel slightly less hungry!<br>$petLine ($minus1/$find_item2[parts] Parts Left)<br><a href=myitems.php?game=$game>Back to Items</a></p>
		</td>
		</tr>
		</table>
		</center>
";
?>